export const activity = {
  data() {
    var checkPresent = (rule, value, callback) => {
      if (!value||!value.length||value.findIndex(n=>n.probability<0||n.probability>100||!n.items)>=0) {
        return callback(new Error(this.$t('activity_form.selectPresent')));
      } else {
        callback()
      }
    };
    var checkCreator = (rule, value, callback) => {
      if (!this.form.creatorId) {
        return callback(new Error(this.$t('formRule.creator_rule')));
      } else {
        callback()
      }
    };
    var checkCards = (rule, value, callback) => {
      if (!value||!value.length) {
        return callback(new Error(this.$t('table_data.selectText')));
      } else {
        callback()
      }
    };
    var checkStartDate = (rule, value, callback) => {
      if (!this.form.startDate) {
        return callback(new Error(this.$t('formRule.time_rule')));
      } else {
        callback()
      }
    };
    var checkEndDate = (rule, value, callback) => {
      if (!this.form.endDate) {
        return callback(new Error(this.$t('formRule.time_rule')));
      } else {
        callback()
      }
    };
    var checkImg = (rule, value, callback) => {
      if (!this.form.thumbnailId) {
        return callback(new Error(this.$t('formRule.poster_rule')));
      } else {
        callback()
      }
    };
    var checkPhoneImg = (rule, value, callback) => {
      if (!this.form.phoneImageId) {
        return callback(new Error(this.$t('formRule.poster_rule')));
      } else {
        callback()
      }
    };
    var checkFile = (rule, value, callback) => {
      if (!this.form.fileId) {
        return callback(new Error(this.$t('formRule.file_rule')));
      } else {
        callback()
      }
    };
    var zh_TW = (rule,value,callback) => {
      if (!this.form.title.zh_TW) {
        return callback(new Error(this.$t('formRule.arttnMovieName')));
      } else {
        callback()
      }
    };
    var en_US = (rule,value,callback) => {
      if (!this.form.title.en_US) {
        return callback(new Error(this.$t('formRule.artusMovieName')));
      } else {
        callback()
      }
    };
    var ja_JP = (rule,value,callback) => {
      if (!this.form.title.ja_JP) {
        return callback(new Error(this.$t('formRule.artjaMovieName')));
      } else {
        callback()
      }
    };
    var zh_CN = (rule,value,callback) => {
      if (!this.form.title.zh_CN) {
        return callback(new Error(this.$t('formRule.artcnMovieName')));
      } else {
        callback()
      }
    };
    var d_zh_TW = (rule,value,callback) => {
      if (!this.form.activityRules.zh_TW) {
        return callback(new Error(this.$t('formRule.inputPlaceholder')));
      } else {
        callback()
      }
    };
    var d_en_US = (rule,value,callback) => {
      if (!this.form.activityRules.en_US) {
        return callback(new Error(this.$t('formRule.inputPlaceholder')));
      } else {
        callback()
      }
    };
    var d_ja_JP = (rule,value,callback) => {
      if (!this.form.activityRules.ja_JP) {
        return callback(new Error(this.$t('formRule.inputPlaceholder')));
      } else {
        callback()
      }
    };
    var d_zh_CN = (rule,value,callback) => {
      if (!this.form.activityRules.zh_CN) {
        return callback(new Error(this.$t('formRule.inputPlaceholder')));
      } else {
        callback()
      }
    };
    return {
      mode: "add",
      theatredKey: '',
      theatreKey: '',
      theatredList: [],
      selectAllTheatred: false,
      selectedNum: 0,
      showTheatre: false,
      isEdit: false,
      showImg: false,
      uploadFileStatus: false,
      uploadingNum: 1,
      pngBlob: [],
      pngIndex: 0,
      showFileDialog: false,
      modelValue: false,
      showUpload: false,
      showPhoneUpload: false,
      scDialogFileData: {
        isDIY: false,
        isDefense: false,
        isUploadedFile: false,//是否已上传
        isPreview: false,
        uploadResponse: '',
        uploadFiles: '',
        imgFiles: [],
        imgPreviewFiles: [],
        page: 3,
        compression: true,
        file: '',
        previewFile: '',
        newImg: ''
      },
      disabled: false,
      creatorIdList: [],
      localeList: [
        {
          country: 'ALL',
          en_US: 'ALL',
          ja_JP: '全て',
          zh_CN: '全部',
          zh_TW: '全部',
        }
        // {
        // 	name: this.$t('artwork_data.locale_japan'),
        // 	value: 0,
        // },
        // {
        // 	name: this.$t('artwork_data.locale_world'),
        // 	value: 1,
        // }
      ],
      langList: [
        {
          name: '简体中文',
          value: 'zh_CN',
        },
        {
          name: '繁體中文',
          value: 'zh_TW',
        },
        {
          name: 'English',
          value: 'en_US',
        },
        {
          name: '日本語',
          value: 'ja_JP',
        }
      ],
      powerList: [
        { 
          name: this.$t('artwork_data.form.power.type1'),
          value: 1||0,
        },
        {
          name: this.$t('artwork_data.form.power.type2'),
          value: 2,
        },
        {
          name: this.$t('artwork_data.form.power.type3'),
          value: 3,
        },
        { 
          name: this.$t('artwork_data.form.power.type4'),
          value: 4,
        },
        {
          name: this.$t('artwork_data.form.power.type5'),
          value: 5,
        },
        {
          name: this.$t('artwork_data.form.power.type6'),
          value: 6,
        }
      ],
      onlyList: [
        { 
          name: 'unique work',
          value: 'unique work',
        },
        {
          name: 'non unique work',
          value: 'non unique work',
        },
        {
          name: 'unknown',
          value: 'unknown',
        }
      ],
      typeList: [
        {
          name: this.$t('artwork_data.form.tcType.number'),
          value: 1,
        },
        {
          name: this.$t('artwork_data.form.tcType.body'),
          value: 2,
        }
      ],
      statusList: [
        {
          name: this.$t('artwork_data.statusType.status1'),
          value: 1,
        },
        {
          name: this.$t('artwork_data.statusType.status2'),
          value: 2,
        },
        {
          name: this.$t('artwork_data.statusType.status3'),
          value: 3,
        },
        {
          name: this.$t('artwork_data.statusType.status4'),
          value: 4,
        }
      ],
      classList: [
        {
          name: this.$t('artwork_data.classification.class1'),
          value: 11,
        },
        {
          name: this.$t('artwork_data.classification.class2'),
          value: 12,
        },
        {
          name: this.$t('artwork_data.classification.class3'),
          value: 13,
        },
        {
          name: this.$t('artwork_data.classification.class4'),
          value: 14,
        },
        {
          name: this.$t('artwork_data.classification.class5'),
          value: 21,
        },
        {
          name: this.$t('artwork_data.classification.class7'),
          value: 15,
        },
        {
          name: this.$t('artwork_data.classification.class6'),
          value: 29,
        }
      ],
      currencyType: [
        {
          value: 1,
          name: this.$t('table_data.currency.jpy'),
        },
        {
          value: 2,
          name: this.$t('table_data.currency.dollar'),
        },
        {
          value: 3,
          name: this.$t('table_data.currency.rmb'),
        },
      ],
      titleMap: {
        add: this.$t('table_data.adduserTitle'),
        edit: this.$t('table_data.userTitle')
      },
      locationArr: [{
        value: 'ja',
        label: 'Japanese'
      }, {
        value: 'en',
        label: 'English'
      }, {
        value: 'chs',
        label: '中文简体'
      }, {
        value: 'cht',
        label: '中文繁體'
      }],
      artworkDesc: {
        en_US: '',
        ja_JP: '',
        zh_CN: '',
        zh_TW: '',
      },
      fileAction: 'fileType',
      action: '#',
      image: null,
      file: null,
      theatreList: [],
      theatreListData: [],
      filterMethod(query, item) {
        return item.label.indexOf(query) > -1;
      },
      defaultTime: [new Date(2000,1,1,23,59,59)],
      isShowSpecialItems: false,
      form: {
        "imageFileId": null,
        "image": '',
        "title": {
          en_US: '',
          ja_JP: '',
          zh_CN: '',
          zh_TW: '',
        },
        "activityRules": {
          en_US: '',
          ja_JP: '',
          zh_CN: '',
          zh_TW: '',
        },
        "startDate": "",
        "endDate": "",
        "prepareTime": "",
        "specialItems": [],
        "eventItems": [],
        "festivalId": null,
        "creatorId": null
      },
      movieData: [],
      uploadForm: {
        movie_id: '',
        start_date: '',
        end_date: '',
        official_site: '',
        information: '',
        fileUrl: null,
        thumbnailUrl: null,
        title: '',
      },
      rules: {
        "title.en_US": [
          {required: true, validator: en_US, trigger:'blur'}
        ],
        "title.ja_JP": [
          {required: true, validator: ja_JP, trigger:'blur'}
        ],
        "title.zh_CN": [
          {required: true, validator: zh_CN, trigger:'blur'}
        ],
        "title.zh_TW": [
          {required: true, validator: zh_TW, trigger:'blur'}
        ],
        "activityRules.en_US": [
          {required: true, validator: d_en_US, trigger:'blur'}
        ],
        "activityRules.ja_JP": [
          {required: true, validator: d_ja_JP, trigger:'blur'}
        ],
        "activityRules.zh_CN": [
          {required: true, validator: d_zh_CN, trigger:'blur'}
        ],
        "activityRules.zh_TW": [
          {required: true, validator: d_zh_TW, trigger:'blur'}
        ],
        "startDate": [
          {required: true, validator: checkStartDate, trigger:'change'}
        ],
        "endDate": [
          {required: true, validator: checkEndDate, trigger:'change'}
        ],
        "fileId": [
          {required: true, validator: checkFile, trigger:'change'}
        ],
        "thumbnailUrl": [
          {required: true, validator: checkImg, trigger:'change'}
        ],
        "phoneImage": [
          {required: true, validator: checkPhoneImg, trigger:'change'}
        ],
        "eventItems":  [
          {required: true, validator: checkCards, trigger:'change'}
        ],
        "specialItems": [
          {required: true, validator: checkPresent, trigger:'change'}
        ],
        "creatorId": [
          {required: true, validator: checkCreator, trigger:'change'}
        ]
      },
      visible: false,
      isSaveing: false
    }
  },
  computed: {
    icon() {
      // return function(){
        const dUrl = decodeURIComponent(this.form.fileUrl);
        const str = dUrl.split('?')[0].split('.');
        console.log('fileType',str[str.length-1]);
        const type = str[str.length-1];
        if(type){
          if(['jpg','jpeg','png','gif','webp','tiff','bmp','heif','svg'].includes(type)){
            return 'sc-icon-img'
          }else if(['mp3','wma','ape'].includes(type)){
            return 'sc-icon-mp3'
          }else if(['mp4','mp5','avi','wmv'].includes(type)){
            return 'sc-icon-video'
          }else if(['pdf','txt','xlsx'].includes(type)){
            return 'sc-icon-pdf'
          }else{
            return 'sc-icon-none'
          }
        }
        return 'sc-icon-none'
      // }
    },
    oicon(){
      return function(e){
        return e
      }
    },
  },
  created(){
  },
  methods: {
    handleBlur(e) {
      // 限制输入范围为 1 到 100
      console.log(e);
      // let num = parseInt(this.form., 10);
      // if (num < 0) {
      //   this.inputValue = 0;
      // } else if (num > 100) {
      //   this.inputValue = 100;
      // }
    },
    beforeOptions(v){
      if(!this.form.endDate)return false
      return v.getTime() > new Date(this.form.endDate).getTime();//  - 86400000是否包括当天
    },
    backOptions(v){
      return v.getTime() < new Date(this.form.startDate).getTime();//  - 86400000是否包括当天
    },
    prepareOptions(v){
      return v.getTime() >= new Date(this.form.startDate).getTime();//  - 86400000是否包括当天
    },
    delDiscount(index){
      this.form.specialItems.splice(index,1)
    },
    addDiscount(){
      this.form.specialItems.push({
        probability: 0,
        items: ""
      })
      // let arr = Math.ceil(this.form.episode / this.episodes);
      // for(let i = 1;i <= this.form.episode; i++){
      //   if((i % this.episodes == 0 && this.form.discount.findIndex(n=>n.episodeNum == i) == -1) || this.form.discount.length+1 == arr && this.form.episode == i){
      //     this.form.specialItems.push({
      //       episodeNum: i,
      //       episodeRate: ''
      //     })
      //     this.setSeries();
      //     break
      //   }
      // }
    },
    setSeries(){
      // this.disList = {}
      // for(let t=0;t<this.form.discount.length;t++){
      //   let index = this.form.discount[t].episodeNum;
      //   for(let i = 1;i <= this.form.episode; i++){
      //     if(!this.disList[index])this.disList[index]=[]
      //     if(i % this.episodes == 0 && this.form.discount.findIndex(n=>n.episodeNum==i) == -1)this.disList[index].push({name:i,value:i})
      //     if(i == this.form.episode && this.form.episode % this.episodes != 0 && this.form.discount[t].episodeNum != i && this.form.discount.findIndex(n=>n.episodeNum==i) == -1)this.disList[index].push({name: this.form.episode,value: this.form.episode})
      //   }
      // }
    },
  }
}
